package com.example.taobao

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_register.*
import kotlinx.android.synthetic.main.newaddress.*
import okhttp3.FormBody
import okhttp3.OkHttpClient
import okhttp3.Request
import java.lang.Exception
import java.net.URLEncoder
import kotlin.concurrent.thread

class Register : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_register)
        btnzhuce.setOnClickListener {
            thread {
                try {
                    val client = OkHttpClient()
                    val requestBody = FormBody.Builder()
                        .add("email", URLEncoder.encode(email.text.toString(), "utf-8"))
                        .add(
                            "username",
                            URLEncoder.encode(zhanghao.text.toString(), "utf-8")
                        )
                        .add("password", URLEncoder.encode(mima.text.toString(), "utf-8"))
                        .build()
                    val request = Request.Builder()
                        .url("http://192.168.43.140:8080/aaa_war_exploded/adduser.jsp")
                        .post(requestBody)
                        .build()
                    val respone = client.newCall(request).execute()
                    val responeData = respone.body?.string()
                } catch (e: Exception) {
                    e.printStackTrace()
                }
            }
            runOnUiThread{
                val intent = Intent()
                intent.setClass(this,Login::class.java)
                startActivity(intent)
            }
        }
    }
}